package com.lee.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter;
import org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/11/29
 */
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http.authorizeRequests()
				.anyRequest().authenticated()
				.and()
				.formLogin()
				.loginPage("/login.html")
				.defaultSuccessUrl("/index")
				.permitAll()
				.and()
				.csrf().disable()
				.oauth2Client();
	}

	@Bean
	public UserDetailsService users() {
//		OAuth2AuthorizationRequestRedirectFilter
//		OAuth2LoginAuthenticationFilte
//		DefaultLoginPageGeneratingFilter
		return new InMemoryUserDetailsManager(User
				.withUsername("javaboy").password("{noop}123").roles("USER").build());
	}
}
